<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 为什么会有promise？解决什么问题？
        // 省市区街道四级联动 =》 回显
        // 复杂化的场景 =》回调地狱（无线层嵌套）
        run(0)
        setTimeout(() =>{
            run(1)
            setTimeout(() =>{
                run(2)
                setTimeout(() =>{
                    run(3)
                },1000)
            },1000)
        },1000)


        new Promise((resolve, reject) =>{
            run(0)
        }).then((res) =>{
            run(1)
        }).then((res) =>{
            run(2)
        }).then((res) =>{
            run(3)
        }).then((res) =>{
            run(4)
        })

        // 2.Promise是什么？
        // 例子：promise  =》 承诺  诺言
        // let getLV = new promise()  //给女朋友承诺

        let isForget = true;
        let getLv = new Promise((resolve, reject) =>{
            if(isForget){
                let lv = {
                    color: 'green',
                    price: '$99'
                }
                // 得到包包
                resolve(lv)
            } else {
                let err = new Error("最近工作太忙了，忘记了")
                reject(err)
            }
        })  //给女朋友许下承诺

            let testFn = function() {
                getLv.then((fulfilled) =>{
                    console.log(fulfilled);
                }).catch((rejected) =>{
                    console.log(rejected.massage);
                })
            }
            testFn()

            let buyLip = (lv) =>{
                let lip = {
                    brand:'我尼玛',
                    color:'pink'
                }
                let msg = {
                    
                }
            }


    </script>
    
</body>
</html>